<?php
/* 
 * ********* CVS HEADER ********* 
 * 
 * $RCSfile: download.php,v $ 
 * $Date: 2005/08/29 14:00:53 $ 
 * $Revision: 1.2 $ 
 * 
 * ********* CVS HEADER ********* 
 */
if($fid!=''){
    $query="SELECT rportal_download.*,rportal_upload_path.path FROM rportal_download,rportal_upload_path,hierarchie WHERE rportal_download.droit=hierarchie.id_groupe AND hierarchie.id_groupe_dessus='$session[id_groupe]' AND rportal_download.id='$fid' AND rportal_download.id_path_upload=rportal_upload_path.id";
}else if($filename!='' && $pathid!=''){
    $query="SELECT rportal_download.*,rportal_upload_path.path FROM rportal_download,rportal_upload_path,hierarchie WHERE rportal_download.droit=hierarchie.id_groupe AND hierarchie.id_groupe_dessus='$session[id_groupe]' AND rportal_download.filename='$filename' AND rportal_download.id_path_upload=rportal_upload_path.id AND rportal_upload_path.id='$pathid'";
}else{
    rportalerreur("le fichier n'est pas defini","?op=");
}
$result=rportalrequete($query) or rportalerreur("le fichier n'est pas defini","?op=");
if(rportalnbresult($result)==0){
    rportalerreur("le fichier n'est pas defini","?op=");
}
$file=rportalligne($result);
$filename=$file['filename']; // the name the file will have on client computer
$file_to_download=$file['path'].$file['fileonserver']; // the name the file has on the server (or an FTP or HTTP request)
$hit = $file['hit']+1;
$query="UPDATE rportal_download SET hit='$hit' WHERE id='".$file['id']."'";
@rportalrequete($query) or rportalerreur("ERREUR : $query","?op=");

header("Content-Type: application/force-download; name=\"$filename\""); 
header("Content-Transfer-Encoding: binary"); 
header("Content-length: ".filesize($file_to_download));
header("Content-Disposition: attachment; filename=\"$filename\""); 
header("Expires: 0"); 
header("Cache-Control: no-cache, must-revalidate"); 
header("Pragma: no-cache"); 
		
readfile($file_to_download);
?>